import { mapState } from 'vuex'

export default {
    data() {
        return {
            userInfo: null
        }
    },
    computed: {
        ...mapState(['user'])
    },
    mounted() {
        $ajax.user.queryUserInfo({
            userId: this.user.userId
        }).then(res => {
            var { code, data } = res.data
            if (code == 'S') {
                this.userInfo = data
            }
        })
    },
    methods: {
        logout() {
            $dialog.confirm({
                content: '是否注销?',
                // 取消按钮文本
                cancelText: '取消',
                // 确定按钮文本,
                okTheme: 'balanced',
                okText: '确定'
            }).then((res) => {
                if (res) {
                    $ajax.account.logout({
                        userId: this.user.userId
                    }).then(res => {
                        var { code, msg } = res.data
                        $toast.show(msg)
                        if (code == 'S') {
                            $store.dispatch('userClear')
                            $router.replace({
                                name: 'user_login'
                            })
                        }
                    })
                }
            })
        }
    },
    mixins: [$mixins.needLogin]
}